package com.jiaquyun.jcps.ui.main

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jiaquyun.jcps.R
import com.jiaquyun.jcps.base.ViewModeFragment
import com.jiaquyun.jcps.mode.vm.MainViewModel
import kotlinx.android.synthetic.main.fragment_main.*

class MainFragment : ViewModeFragment<MainViewModel>() {

    private val taskAdapter =
        object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_order_task) {
            init {
                addChildClickViewIds(R.id.tvTaskReceiveOrder)
            }

            override fun convert(holder: BaseViewHolder, item: String) {

            }
        }

    private val pickupAdapter =
        object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_order_pickup) {
            init {
                addChildClickViewIds(R.id.tvPickupContactClient, R.id.tvPickupConfirmOrder)
            }

            override fun convert(holder: BaseViewHolder, item: String) {

            }
        }

    private val giveAdapter =
        object : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_order_give) {
            init {
                addChildClickViewIds(
                    R.id.ivGiveNavigation,
                    R.id.tvGiveContactClient,
                    R.id.tvGiveConfirmService
                )
            }

            override fun convert(holder: BaseViewHolder, item: String) {

            }
        }

    companion object {
        private const val KEY_STATUS = "KEY_STATUS"
        fun newInstance(status: Int): MainFragment {
            val bundle: Bundle = Bundle().apply {
                putInt(KEY_STATUS, status)
            }
            return MainFragment().apply {
                arguments = bundle
            }
        }
    }

    override fun viewModel(): MainViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_main

    override fun initView() {
        rvMainBody.adapter = when (arguments?.getInt(KEY_STATUS, (0))) {
            2 -> pickupAdapter
            3 -> giveAdapter
            else -> taskAdapter
        }

        taskAdapter.setOnItemChildClickListener { adapter, view, position -> }

        pickupAdapter.setOnItemChildClickListener { adapter, view, position -> }

        giveAdapter.setOnItemChildClickListener { adapter, view, position -> }
    }

    override fun initData() {
        when (arguments?.getInt(KEY_STATUS, (0))) {
            2 -> pickupAdapter.setNewInstance(mutableListOf("", "", ""))
            3 -> giveAdapter.setNewInstance(mutableListOf("", "", ""))
            else -> taskAdapter.setNewInstance(mutableListOf("", "", ""))
        }
    }

    override fun initViewMode() {
        when (arguments?.getInt(KEY_STATUS, (0))) {
            2 -> {
            }
            3 -> {
            }
            else -> {
            }
        }
    }

//    override fun initViewMode() {
//        viewModel.OrderListEntityDataLiveData.observe(viewLifecycleOwner, Observer { order ->
//            LogUtils.e("============ddd======${GsonUtils.toJson(order)}")
//        })
//    }
}